﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ContactSMS.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class PhoneRecord : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<long>(
                name: "UpdateTime",
                table: "T_Phone",
                type: "bigint",
                nullable: false,
                comment: "更新时间",
                oldClrType: typeof(int),
                oldType: "int",
                oldComment: "更新时间");

            migrationBuilder.AlterColumn<long>(
                name: "CreatTime",
                table: "T_Phone",
                type: "bigint",
                nullable: false,
                comment: "创建时间",
                oldClrType: typeof(int),
                oldType: "int",
                oldComment: "创建时间");

            migrationBuilder.AlterColumn<long>(
                name: "UpdateTime",
                table: "T_Contact",
                type: "bigint",
                nullable: false,
                comment: "更新时间",
                oldClrType: typeof(int),
                oldType: "int",
                oldComment: "更新时间");

            migrationBuilder.AlterColumn<long>(
                name: "CreatTime",
                table: "T_Contact",
                type: "bigint",
                nullable: false,
                comment: "创建时间",
                oldClrType: typeof(int),
                oldType: "int",
                oldComment: "创建时间");

            migrationBuilder.CreateTable(
                name: "T_PhoneRecord",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Mobile = table.Column<string>(type: "VARCHAR(20)", nullable: false, comment: "电话")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreatTime = table.Column<long>(type: "bigint", nullable: false, comment: "创建时间"),
                    UpdateTime = table.Column<long>(type: "bigint", nullable: false, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_PhoneRecord", x => x.Id);
                },
                comment: "拨打电话记录表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_T_Phone_ContactId",
                table: "T_Phone",
                column: "ContactId");

            migrationBuilder.AddForeignKey(
                name: "FK_T_Phone_T_Contact_ContactId",
                table: "T_Phone",
                column: "ContactId",
                principalTable: "T_Contact",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_T_Phone_T_Contact_ContactId",
                table: "T_Phone");

            migrationBuilder.DropTable(
                name: "T_PhoneRecord");

            migrationBuilder.DropIndex(
                name: "IX_T_Phone_ContactId",
                table: "T_Phone");

            migrationBuilder.AlterColumn<int>(
                name: "UpdateTime",
                table: "T_Phone",
                type: "int",
                nullable: false,
                comment: "更新时间",
                oldClrType: typeof(long),
                oldType: "bigint",
                oldComment: "更新时间");

            migrationBuilder.AlterColumn<int>(
                name: "CreatTime",
                table: "T_Phone",
                type: "int",
                nullable: false,
                comment: "创建时间",
                oldClrType: typeof(long),
                oldType: "bigint",
                oldComment: "创建时间");

            migrationBuilder.AlterColumn<int>(
                name: "UpdateTime",
                table: "T_Contact",
                type: "int",
                nullable: false,
                comment: "更新时间",
                oldClrType: typeof(long),
                oldType: "bigint",
                oldComment: "更新时间");

            migrationBuilder.AlterColumn<int>(
                name: "CreatTime",
                table: "T_Contact",
                type: "int",
                nullable: false,
                comment: "创建时间",
                oldClrType: typeof(long),
                oldType: "bigint",
                oldComment: "创建时间");
        }
    }
}
